import Cookies from 'js-cookie'

const TokenKey = 'medical_token'
const UserTypeKey = 'user_type'

export function getToken() {
  return localStorage.getItem('token')
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

export function getUserType() {
  const userInfo = localStorage.getItem('userInfo')
  if (userInfo) {
    try {
      const { type } = JSON.parse(userInfo)
      return type
    } catch (e) {
      return null
    }
  }
  return null
}

export function setUserType(type) {
  return Cookies.set(UserTypeKey, type)
}

export function removeUserType() {
  return Cookies.remove(UserTypeKey)
}

export function clearAuth() {
  localStorage.removeItem('token')
  localStorage.removeItem('userInfo')
  removeToken()
  removeUserType()
} 